home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / sox / amiga.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  1KB  |  53 lines

  1. /* tmpfile() function for AmigaDOS.
  2.  * Not needed with SAS/C 6.0 and higher, but included for
  3.  * the benefit of people with pther compilers who might
  4.  * want it.
  5.  * All rights to this code are relinquished to the public domain.
  6.  * --D. Champion, 13 Jan 1993
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/tasks.h>
  11. #include <stdio.h>
  12.  
  13. #ifndef P_tmpdir
  14. #define P_tmpdir    "t:"
  15. #define B_tmpnam    5
  16. #undef L_tmpnam
  17. #define L_tmpnam    sizeof(P_tmpdir)+B_tmpnam+21
  18.     /* sizeof(P_tmpdir) includes terminating null; B_tmpnam is how much   *
  19.      * of myname to include; 8x2 for hex longs + 3 dots + 2 sequence nums */
  20. #endif
  21.  
  22. char tmpnam_count=0;
  23.  
  24. char *tmpnam(char *s)
  25. {
  26. extern char *myname;    /* myname MUST exist! */
  27. extern char tmpnam_count;
  28. char *uniqsuff=".00000000.00000000.00";
  29. int i;
  30.  
  31. strcpy (s,P_tmpdir);
  32. strncat(s,myname,B_tmpnam);    /* start tmpfilename with 1st B_tmpnam chars of myname */
  33. sprintf(uniqsuff,".%8x.%8x.%2x\0",(ULONG)FindTask(NULL),(ULONG)time(),(char)tmpnam_count);
  34. for(i=0;i<L_tmpnam+B_tmpnam;i++) {
  35.     if (uniqsuff[i]==' ') uniqsuff[i]='0';
  36. }
  37. strcat (s,uniqsuff);
  38. tmpnam_count++;
  39.  
  40. return(s);
  41. }
  42.  
  43. /* Note that tmpfile() does not yet know how to delete files! Sorry, *
  44.  * but I haven't yet found a way to make it track the files it opens *
  45.  * (then close them, if necessary) and delete them.  Maybe soon....  */
  46. FILE *tmpfile(void)
  47. {
  48. FILE *file;
  49. char fnam[L_tmpnam];
  50.  
  51. return(file=fopen(tmpnam(fnam),"wb+"));
  52. }
  53.